package com.liusy.code.bean;

import org.eclipse.jdt.core.IPackageFragment;

/**
 * 包信息
 * @author yangzhibin
 *
 */
public class PackageNameInfo
{
	private String entityPackageName;//entity包名
	private String modeName;//模块名
	private String jspPath="/";//jsp页面路径

	/**
	 * 构造方法
	 * @param packageFragment
	 */
	public PackageNameInfo(IPackageFragment packageFragment)
	{
		this.entityPackageName = packageFragment.getElementName();
		//String basePackageName = entityPackageName.substring(0, entityPackageName.lastIndexOf("."));
		//this.modeName = basePackageName.substring(basePackageName.lastIndexOf(".") + 1, basePackageName.length());//模块名
		this.modeName = entityPackageName.substring(entityPackageName.lastIndexOf(".") + 1, entityPackageName.length());//模块名
	}

	public String getJspPath() {
		return jspPath;
	}

	public void setJspPath(String jspPath) {
		this.jspPath = jspPath;
	}

	/**
	 * 获取实体类包名
	 * @return
	 */
	public String getEntityPackageName()
	{
		return getPackageName(entityPackageName, "domain");
	}

	/**
	 * 获取dao包名
	 * @return
	 */
	public String getDaoPackageName()
	{
		return getPackageName(entityPackageName, "dao");
	}
	
	/**
	 * 获取dao包名
	 * @return
	 */
	public String getDaoImplPackageName()
	{
		return getPackageName(entityPackageName, "dao.impl");
	}

	/**
	 * 获取service包名
	 * @return
	 */
	public String getServicPackageName()
	{
		return getPackageName(entityPackageName, "service");
	}
	
	/**
	 * 获取service包名
	 * @return
	 */
	public String getServicImplPackageName()
	{
		return getPackageName(entityPackageName, "service.impl");
	}

	/**
	 * 获取action包名
	 * @return
	 */
	public String getActionPackageName()
	{
		return getPackageName(entityPackageName, "action");
	}

	/**
	 * 获取模块名
	 * @return
	 */
	public String getModeName()
	{
		return modeName;
	}

	/**
	 * 取得包名
	 * @param entityPackageName
	 * @param type
	 * @return
	 */
	private String getPackageName(String entityPackageName, String type)
	{
		return entityPackageName + "." + type;
//		if (entityPackageName.indexOf(".") != -1)
//		{
//			//int index = entityPackageName.lastIndexOf(".");
//			//return entityPackageName.substring(0, index) + "." + type;
//			return entityPackageName + "." + type;
//		} else
//		{
//			return type;
//		}
	}

}
